package com.javafactroy.kunlong.bip.icp.context.connpool.dxpftp;

import com.javafactroy.kunlong.bip.icp.common.config.BipPoolConfig;
import com.javafactroy.kunlong.bip.icp.ftpclient.dxp.DxpFtpTemplate;
import lombok.Data;
import org.apache.commons.pool2.impl.GenericObjectPool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
//@Scope("prototype")
@Data
public class DxpFtpTemplatePool {
    @Autowired
    DxpFtpTemplateFactory factory;
    @Autowired
    BipPoolConfig poolConfig;

    volatile  static GenericObjectPool<DxpFtpTemplate> objectPool;

    synchronized GenericObjectPool<DxpFtpTemplate> getDxpFtpTemplatePool() {
        if (objectPool == null) {

            synchronized (DxpFtpTemplatePool.class) {
                if (objectPool == null) {
                    objectPool = new GenericObjectPool<DxpFtpTemplate>(factory, poolConfig);

                }
            }
        }
        return objectPool;
    }

    public DxpFtpTemplatePool() {

    }

    public DxpFtpTemplate borrowObject() throws Exception {

        return getDxpFtpTemplatePool().borrowObject();
    }

    public void returnObject(DxpFtpTemplate DxpFtpTemplate) {

        getDxpFtpTemplatePool().returnObject(DxpFtpTemplate);

    }
}










